/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.util;

import java.util.Random;

public class ExponentialDistribution implements Distribution{
	private final Random random;
	private final double mu;

	public ExponentialDistribution(long seed, double mu) {
		if(mu <= 0.0){
			throw new IllegalArgumentException("Illegal lambda parameter!");
		}
		random = new Random(seed+System.currentTimeMillis());
		this.mu = mu;
	}
	
	public ExponentialDistribution(double mu){
		if(mu <= 0.0){
			throw new IllegalArgumentException("Illegal lambda parameter!");
		}
		random = new Random(System.currentTimeMillis());
		this.mu = mu;
	}

	public double sample() {
		return -mu * Math.log(random.nextDouble());
	}

	/**
	 * @return the random
	 */
	public Random getRandom() {
		return random;
	}

	/**
	 * @return the lambda
	 */
	public double getLambda() {
		return mu;
	}

}
